package com.starview.star.compiler.cafe.compile.cont;


import com.starview.platform.data.type.Location;
import com.starview.star.compiler.ErrorReport;
import com.starview.star.compiler.cafe.compile.CafeDictionary;
import com.starview.star.compiler.cafe.compile.CodeContext;
import com.starview.star.compiler.cafe.compile.ISpec;
import com.starview.star.compiler.cafe.compile.Types;

public class ReconcileCont implements IContinuation
{
  IContinuation outward;
  ISpec spec;

  public ISpec getSpec()
  {
    return spec;
  }

  public ReconcileCont(IContinuation outward)
  {
    this.outward = outward;
  }

  @Override
  public ISpec cont(ISpec src, CafeDictionary cxt, Location loc, ErrorReport errors, CodeContext ccxt)
  {
    if (spec == null)
      spec = src;
    else if (!src.getJavaType().equals(spec.getJavaType())) {
      if (!src.getJavaType().equals(Types.IVALUE) && !spec.getJavaType().equals(Types.IVALUE))
        errors.reportError("returned type: " + src + " not consistent with earlier case, of type " + spec + " at "
            + loc, src.getLoc(), spec.getLoc());
    }
    return outward.cont(src, cxt, loc, errors, ccxt);
  }

  @Override
  public boolean isJump()
  {
    return outward.isJump();
  }
}